#! /bin/bash

master_container="c_robots_db"

chmod 755 ./docker-compose
./docker-compose down
docker rmi robots_db:latest robots_front:latest robots_server:latest
sudo rm -rf ./robots_db/db/conf/* ./robots_db/db/logs/* ./robots_db/db/data/*
./docker-compose build
./docker-compose up -d

sleep 20
priv_stmt='GRANT REPLICATION SLAVE ON *.* TO "root"@"%" IDENTIFIED BY "1234qwer!"; FLUSH PRIVILEGES;'
docker exec $master_container sh -c "export MYSQL_PWD='1234qwer!';mysql -u root -e '$priv_stmt' "
docker exec $master_container sh -c "export MYSQL_PWD='1234qwer!';mysql -u root -e 'create database robox_web ; '"
docker exec $master_container sh -c "export MYSQL_PWD='1234qwer!';mysql -u root robox_web <data.sql"


docker restart c_robots_server
echo -e "\033[42;34m finish success !!! \033[0m"